package com.szy.web.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import com.szy.web.dao.ClientUserDao;
import com.szy.web.util.TextUtility;

public class clientUserLoginServlet extends HttpServlet {
	private static final long serialVersionUID = -7811568044252827351L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		throw new NotImplementedException();
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		response.setContentType("text/html;charset=UTF-8");
		String classname = request.getParameter("class");
		String username = request.getParameter("username");
		classname = TextUtility.toUTF8(classname);
		username = TextUtility.toUTF8(username);
		System.out.println("class = "+  classname);
		JSONObject jObject = new JSONObject();
		ClientUserDao clientUserDao;	

		try
		{
			clientUserDao = new ClientUserDao();	
			if (	!clientUserDao.validate(classname, username) )
			{
				jObject.put("ret", 0);
			    jObject.put("msg", "ok");
				jObject.put("data", "");
			}
			else 
			{
				jObject.put("ret", 1);
				jObject.put("msg", "error");
				jObject.put("data", "");
			}
			
		} catch (Exception e)
		{
			e.printStackTrace();
			try
			{
				jObject.put("ret", 1);
				jObject.put("msg", "error");
				jObject.put("data", "");
			} catch (JSONException ex)
			{
				ex.printStackTrace();
			}
		}

		PrintWriter out = response.getWriter();
		out.println(jObject);
		out.flush();
		out.close();
	}
		
}	

